/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package helloplashmask;

import plash.display.Sprite;
import plash.display.Stage;
import plash.events.Event;
import plash.events.IEventListener;
import plash.events.MouseEvent;
import plash.geom.Point;
import plash.geom.Rectangle;
import plash.text.TextField;
import plash.utils.Logger;

/**
 *
 * @author User
 */
public class MaskTestStage extends Stage implements IEventListener
{

    private boolean _mask = false;
    private Masker _masker = new Masker();
    private Masked _masked = new Masked();
    private SimpleBox _simpleBox = new SimpleBox();
//    private TextField _tf = new TextField();
    private Sprite _bounds = new Sprite();

    public MaskTestStage()
    {
        _startMusic();
    }

    private void _startMusic()
    {
        _masker.setName("Masker");
        _masked.setName("Masked");
        _simpleBox.setName("SimpleBox");
//        _tf.setName("textField");

//        _tf.setText("Hello Plash!");
//        _tf.setBorder(false);


        _masked.addChild(_simpleBox);
//        this.addChild(_tf);

        this.addChild(_masker);
        this.addChild(_masked);
        this.addChild(_bounds);

        _masked.setLocation(new Point(100, 100));
        _simpleBox.setLocation(new Point(75, 75));

//        _tf.setMask(_masker);
//        _simpleBox.setMask(_masker);
//        _masked.setMask(_masker);
//        _masked.setMask(_tf);

        _masked.addEventListener(MouseEvent.MOUSE_DOWN, this);
        _masker.addEventListener(MouseEvent.MOUSE_MOVE, this);
    }

    @Override
    public void mouseMoved()
    {
        _masker.setX(mouseX);
        _masker.setY(mouseY);
        
//        _tf.setX(mouseX);
//        _tf.setY(mouseY);
    }

    @Override
    public void event(Event e)
    {
        if (e.name.equals(MouseEvent.MOUSE_DOWN))
        {
            _mask = !_mask;
            if (_mask)
            {
                _masked.setMask(_masker);
            }
            else
            {
                _masked.setMask(null);
            }
        }
    }
}
